$(function() {
	//上传公司logo
	var fileFlag;
	$("#logo").change(function(){
		var objUrl;
		if(isIE = navigator.userAgent.indexOf("MSIE 8")!=-1) { 
			objUrl=1;
		}else{
			objUrl = getObjectURL(this.files[0]) ;
			if(this.files[0].size/1024>3000){
				delayURL("简历文件不大于3M。", "3", "");
				return;
			}
		}
		var companyPic = $("#logo").val();
		var extStart=companyPic.lastIndexOf(".");
	    var ext=companyPic.substring(extStart,companyPic.length).toUpperCase();
	    if(ext!=".BMP"&&ext!=".PNG"&&ext!=".GIF"&&ext!=".JPG"&&ext!=".JPEG"){
	    	delayURL("图片限于bmp,png,gif,jpeg,jpg格式", "3", "");
	    	return;
	    }
		if(objUrl!=null) {
			if(objUrl!=1){
				$("#logoShow img").attr("src", objUrl);
			}
			if(companyPicFlag==1){
				deleteFile(companyPicName,2);
	            $.ajax({  
	        	       type : 'post',  
	        	       url : 'saveCompanyInfo.action',  
	        	       dataType : 'json',  
					   data : {
							params : uidAndSession
									+ '&flag=uploadCompanyPic'
									+ '&corpid='
									+ corpid
									+ '&company.logo=0'
						},
	        	  	   success : function (result) {
	        	  	   	   if(result.errcode==0){
	        	  	   		   ajaxFileUpload(2);
	        	  	   	   }
	        	       },  
	        	       error : function () {  
	        	       		return;
	        	       }  
	           });
			}else{
				ajaxFileUpload(2);
			}
		}
	}) ;
	function deleteFile(fileName,fileFlag) {
	    if(fileFlag==2){
			fileName = companyPicName;
		}
	    $.ajax({  
		       type : 'post',  
		       url : 'deleteFile.action',  
		       dataType : 'json',  
		       data :  {"fileName":fileName,"fileFlag":fileFlag},
		  	   success : function (result) {
		  	   	   if(result.errcode==0){
		  	   	   }
		       },  
		       error : function () {  
		       		return;
		       }  
	   });
	}
	function getObjectURL(file) {
		var url = null ; 
		if (window.createObjectURL!=undefined) { // basic
			url = window.createObjectURL(file) ;
		} else if (window.URL!=undefined) { // mozilla(firefox)
			url = window.URL.createObjectURL(file) ;
		} else if (window.webkitURL!=undefined) { // webkit or chrome
			url = window.webkitURL.createObjectURL(file) ;
		}
		return url ;
	}
	function ajaxFileUpload(fileFlag) {
	    // 开始上传文件时显示一个图片
	    $("#wait_loading").ajaxStart(function() {
	        $(this).show();
	    // 文件上传完成将图片隐藏起来
	    }).ajaxComplete(function() {
	        $(this).hide();
	    });
	    if(fileFlag==2){
			fileName = companyPicName;
			fileElementId = "logo";
		}
	    //var elementIds=["flag"]; //flag为id、name属性名
	    $.ajaxFileUpload({
	        url: 'UploadFile.action', 
	        type: 'post',
	        data: {"fileName":fileName,"fileFlag":fileFlag},
	        dataType : 'text',  //返回值类型，一般设置为json、application/json
	        //secureuri: false, //一般设置为false
	        fileElementId: fileElementId, // 上传文件的id、name属性名
	        //elementIds: elementIds, //传递参数到服务器
	        success: function(result){  
	        	result = JSON.parse(result);
	            if(result.errcode==0){
	            	if(fileFlag==2){
	            		url = "saveCompanyInfo.action";
	            	}
	                $.ajax({  
	            	       type : 'post',  
	            	       url : url,  
	            	       dataType : 'json',  
	            	       data :  {	params : uidAndSession
				       					+ '&flag=uploadCompanyPic'
				    					+ '&corpid='
				    					+ corpid
				    					+ '&company.logo='
				    					+result.imgSrc2
	    					},
	            	  	   success : function (result) {
	            	  	   	   if(result.errcode==0){
	            	  	   		   window.open("./myCompany.jsp","_top");
	            	  	   	   }
	            	       },  
	            	       error : function () {  
	            	    	    delayURL("上传失败,请刷新页面后再次上传！","3","");
	            	       		return;
	            	       }  
	               });
	            }else if(result.errcode=="40003"){
	            	delayURL("图片上传失败！","3","");
	            }
	        },
	        error: function(result){ 
	        	return;
	        	//delayURL("图片上传失败！","3","");
	        }
	    });
	    //return false;
	}
	
	//编辑公司信息-左上角
	$('#editCompanyDetail').click(function() {
		$("#companyShortName").attr("value",$('#corpalias').text());
		$("#companyName").attr("value",$('#corpname').text());
		$("#companyFeatures").attr("value",$('#slogan').text());
		$(this).hide();
		$('.c_detail').addClass('c_detail_bg');
		$('.c_box .oneword').hide();
		$('.editDetail').show();
	});
	//取消编辑公司信息
	$('#cancelDetail').click(function() {
		$('#editCompanyDetail').show();
		$('.c_box .oneword').show();
		$('.editDetail').hide();
		if ($('#addLabels').css('display') == 'none') {
			$('.c_detail').removeClass('c_detail_bg');
		}
	});
	/*********************************保存 编辑公司信息*******************************************/
	$('#companyFeatures').focus(function() {
		$('span.error').hide();
	})
	$("#editDetailForm").validate(
		{
			onkeyup : false,
			// focusCleanup:true,
			rules : {
				companyShortName : {
					required : true,
					specialchar : true,
					maxlenStr : 40
				},
				companyFeatures : {
					required : true,
					checkNum : true,
					rangeLenStr : [ 5, 50 ]
				}
			},
			messages : {
				companyShortName : {
					required : "请输入公司简称",
					specialchar : "请输入有效的公司简称，如：金融圈",
					maxlenStr : "请输入40字以内的公司简称"
				},
				companyFeatures : {
					required : "请输入5-50字的一句话介绍",
					/*
					 * minlength:"请输入5-50字的一句话介绍",
					 * maxlength:"请输入5-50字的一句话介绍"
					 */
					checkNum : "请输入有效的一句话介绍",
					rangeLenStr : "请输入5-50字的一句话介绍"
				}
			},
			submitHandler : function(form) {
				var uidAndSession = "uid=" + $.cookie("jrqUid")
						+ "&sessionId=" + $.cookie("sessionId");
				var corpid = $.cookie("corpid");
				var companyName = $('#companyName').val() != $(
						'#companyName').attr("placeholder") ? $(
						'#companyName').val() : '';
				var companyShortName = $('#companyShortName').val() != $(
						'#companyShortName').attr("placeholder") ? $(
						'#companyShortName').val()
						: '';
				var companyFeatures = $('#companyFeatures').val() != $(
						'#companyFeatures').attr("placeholder") ? $(
						'#companyFeatures').val()
						: '';
				$(form).find(":submit").attr("disabled", true);
				$.ajax({  
	        	       type : 'post',  
	        	       url : 'saveCompanyInfo.action',  
	        	       dataType : 'json',  
					   data : {
							params : uidAndSession
							+ '&flag=editDetailForm'
							+ '&corpid='
							+ corpid
							+ '&company.corpname='
							+ companyName
							+ '&company.corpalias='
							+ companyShortName
							+ '&company.slogan='
							+ companyFeatures
						},
	        	  	   success : function (result) {
	        	  		 if(result.errcode==0){
	 	            		if(result.corpalias != ''){
	 	            			$('.c_box h2').text(result.corpalias);
	 	            			$('.c_box h2').attr("title",result.corpalias);
	 	            			/*$('.c_box h1.fullname').show()*/
	 	            			$('.c_box h1.fullname').css('display','block');//bug69参数验证
	 	            		}else{
	 	            			$('.c_box h2').text($('.c_box h1.fullname').text());
	 	            			$('.c_box h2').attr("title",$('.c_box h1.fullname').attr("title"));
	 	            			$('.c_box h1.fullname').hide();
	 	            		}
	 	            		$('.oneword span').text(result.slogan);
	 	            		if($('#addLabels').css("display") == 'none'){
	 	            			$('.editDetail').hide();
	 	            			$('#editCompanyDetail').show();
	 	            			$('.c_detail').removeClass('c_detail_bg');
	 	            			$('.c_box .oneword').show();
	 	            		}else{
	 	            			$('.editDetail').hide();
	 	            			$('#editCompanyDetail').show();
	 	            			$('.c_box .oneword').show();
	 	            		}
	 	            		$('#corpname').text($('#companyName').val());
	 	            	}else{
	 						$('#beError').text(result.errmsg).show();
	 	            	}
	 	            	$(form).find(":submit").attr("disabled", false);
	        	       },  
	        	       error : function () {  
	        	       		return;
	        	       }  
	           });
		}
	});
	//编辑公司介绍
	$('.newIntro #companyProfile').bind('keyup',
		function() {
			if (1000 - $('.newIntro .word_count ').find('span').html() > 20
					|| 1000 - $('.newIntro .word_count ').find('span')
							.html() == 20) {
				$('.newIntro span.error').hide();
			}
	});
	$('#Profile').on(
		'click',
		'#editIntro,#addIntro',
		function() {
			// add nancy
			$('.newIntro #companyDesForm span.error').hide();
			// end nancy
			var profileWrap = $(this).parents('.profile_wrap');
			var c_intro = $("dl:nth-child(3) .c_intro", profileWrap)
					.html();
			if (c_intro) {
				c_intro = $.trim(c_intro.replace(/<br>/gi, '\r\n'));
			}
			$("dl:nth-child(2) textarea", profileWrap).val(c_intro);
			$("dl:nth-child(2) .word_count", profileWrap).children(
					'span').text(
					1000 - $.trim($("dl:nth-child(2) textarea",
							profileWrap).val()).length);
			$("dl:nth-child(1)", profileWrap).hide();
			$("dl:nth-child(2)", profileWrap).show();
			$("dl:nth-child(3)", profileWrap).hide();

	});
	//取消公司介绍
	$('#companyDesForm').click(function(e) {
		e.stopPropagation();
	})
	$('#delProfile').bind('click',
		function(e) {
			var profileWrap = $(this).parents(".profile_wrap");
			if ($('.c_intro', profileWrap).html() == '') {
				$("dl:nth-child(1)", profileWrap).show();
				$("dl:nth-child(2)", profileWrap).hide();
				$("dl:nth-child(3)", profileWrap).hide();
			} else {
				$("dl:nth-child(1)", profileWrap).hide();
				var oldVal = $("dl:nth-child(3)", profileWrap).find(
						'.c_intro').text();
				$("dl:nth-child(2)", profileWrap).find('#companyProfile')
						.val(oldVal);
				$("dl:nth-child(2)", profileWrap).hide();
				$("dl:nth-child(3)", profileWrap).show();
			}
	});
	$('#companyDesForm').submit(
		function() {
			if ($('textarea', this).val() == $('textarea', this)
					.attr('placeholder')) {
				$('textarea', this).val("");
			}
		}).validate(
		{
			onkeyup : false,
			// focusCleanup:true ,
			onfocusout : false,
			onsubmit : true,
			rules : {
				companyProfile : {
					required : false,
					/* rangeLen: [20,1000] */
					rangeLenStr : [ 10, 1000 ]
				}
			},
			messages : {
				companyProfile : {
					/* rangeLen:"请输入20-1000字的公司介绍" */
					rangeLenStr : "请输入10-1000字的公司介绍"
				}
			},
			submitHandler : function(form) {
				var uidAndSession = "uid=" + $.cookie("jrqUid")
						+ "&sessionId=" + $.cookie("sessionId");
				var corpid = $.cookie("corpid");
				var companyProfile = $.trim($('#companyProfile')
						.val()) != $('#companyProfile').attr(
						'placeholder') ? $
						.trim($('#companyProfile').val()) : '';
				var profileWrap = $(form).parents(".profile_wrap");
				companyProfile = companyProfile.replace(/\r\n/g,
						'<br />');
				companyProfile = companyProfile.replace(/\n/g,
						'<br />');
				$(form).find(":submit").attr("disabled", true);
				$.ajax({  
	        	       type : 'post',  
	        	       url : 'saveCompanyInfo.action',  
	        	       dataType : 'json',  
					   data : {
						   params : uidAndSession
							+ '&flag=companyDesForm'
							+ '&corpid='
							+ corpid
							+ '&company.intro='
							+ encodeURI(companyProfile)
						},
	        	  	   success : function (result) {
	        	  		 if(result.errcode==0){
	                 		if(result.intro == ''){
	                 			$("dl:nth-child(1)",profileWrap).show();
	                 			$("dl:nth-child(2) textarea",profileWrap).val("");
	                 			$("dl:nth-child(2)",profileWrap).hide();
	                 			$("dl:nth-child(3) .c_intro",profileWrap).html("");
	                 			$("dl:nth-child(3)",profileWrap).hide();
	                 		}else{
	                 			$("dl:nth-child(1)",profileWrap).hide();
	                 			var remark = result.intro;
	                 			if(remark){
	                 				remark =  $.trim(remark.replace(/<br \/>/gi,''));
	     						}
	                 			$("dl:nth-child(2) textarea",profileWrap).val(remark);
	                 			$("dl:nth-child(2)",profileWrap).hide();
	                 			$("dl:nth-child(3) .c_intro",profileWrap).html(result.intro);
	                 			$("dl:nth-child(3)",profileWrap).show();
	                 		}
	                 	}else{
	                 		alert("保存失败");
	                 	}
	                 	$(form).find(":submit").attr("disabled", false);
	        	       },  
	        	       error : function () {  
	        	       		return;
	        	       }  
	           });
		}
	});
	//编辑公司信息(右侧)
	$('#editTags').click(function() {
		$('#c_tags_show').hide();
		$('#c_tags_edit').show();
		$("#workCity").attr("value",city);
		$("#select_ind").attr("value",industryField);
		$("#select_sca").attr("value",companySize);
		$("#companyUrl").attr("value",companyUrl);
	});
	//取消修改右侧
	$('#cancelFeatures').click(function() {
		$('#c_tags_edit').hide();
		$('#c_tags_show').show();
	});
	
	$('#tagForms').validate(
	{
		/*
		 * onkeyup: false, focusCleanup:true,
		 */
		rules : {
			city : {
				required : true,
				checkCity : true,
				maxlenStr : 10
			},
			industryField : {
				required : false
			},
			companySize : {
				required : false
			},
			companyUrl : {
//				required : true,
				checkUrl : true,
				maxlength : 120
			}
		},
		messages : {
			city : {
				required : "请输入公司所在城市，如：北京",
				/* maxlength:"请输入20字符以内的公司地址" */
				maxlenStr : "请输入有效的公司所在城市，如：北京"
			},
			industryField : {
				required : "请选择公司行业领域"
			},
			companySize : {
				required : "请选择公司规模"
			},
			companyUrl : {
				required : "请输入公司网址，如：www.jrq.cn",
				checkUrl : "请输入有效的公司网址",
				maxlength : "请输入120字符以内的网址"
			}
		},
		errorPlacement : function(label, element) {
			if (element.attr("type") == "hidden") {
				label.insertAfter($(element).parent());
			} else {
				label.insertAfter(element);
			}
		},
		submitHandler : function(form) {
			var uidAndSession = "uid=" + $.cookie("jrqUid")
					+ "&sessionId=" + $.cookie("sessionId");
			var corpid = $.cookie("corpid");
			var city = $('#workCity', form).val();
			var industryField = $('#industryField', form).val();
			if(industryField==""){
				industryField = $("#select_ind").val();
			}
			if(industryField=="计算机/软件")
			{
				industryField = 394;
			}else if(industryField=="互联网/运营"){
				industryField =395;
			}else if(industryField=="客服"){
				industryField = 396;
			}else if(industryField=="销售"){
				industryField = 397;
			}else if(industryField=="职能"){
				industryField = 398;
			}else if(industryField=="其他"){
				industryField = 399;
			} 
			var companySize = $('#companySize', form).val();
			if(companySize==""){
				companySize = $("#select_sca").val();
			}
			if(companySize=="少于15人")
			{
				companySize = 0;
			}else if(companySize=="15-50人"){
				companySize = 1;
			}else if(companySize=="50-150人"){
				companySize = 2;
			}else if(companySize=="150-500人"){
				companySize = 3;
			}else if(companySize=="500-2000人"){
				companySize = 4;
			}else if(companySize=="2000人以上"){
				companySize = 5;
			}
			var companyUrl = $('#companyUrl', form).val();
			$(form).find(":submit").attr("disabled", true);
			$.ajax({  
     	       type : 'post',  
     	       url : 'saveCompanyInfo.action',  
     	       dataType : 'json',  
				   data : {
						params : uidAndSession
						+ '&flag=tagForms'
						+ '&corpid='
						+ corpid
						+ '&company.city='
						+ city
						+ '&company.corpindustry='
						+ industryField
						+ '&company.corpscale='
						+ companySize
						+ '&company.website='
						+ companyUrl
					},
     	  	   success : function (result) {
     	  		if(result.errcode==0){
            		$('#city',form).val(city);
            		$('#industryField',form).val(industryField);
            		$('#companySize',form).val(companySize);
            		$('#companyUrl',form).val(companyUrl);
            		$('#comCity',form).val(city);
            		$('#comInd',form).val(industryField);
            		$('#comSize',form).val(companySize);
            		$('#comUrl',form).val(companyUrl);
            		if(companyUrl.indexOf('http://') != -1 || companyUrl.indexOf('https://') != -1){
            			$('#c_tags_show table').html('<tr><td>地点</td><td>'+result.city+'</td></tr>'+
                                '<tr><td>领域</td><td>'+result.corpindustry+'</td></tr>'+
                                '<tr><td>规模</td><td>'+result.corpscale+'</td></tr>'+
                                '<tr><td>主页</td><td><a href="'+result.website+'" target="_blank">'+result.website+'</a></td></tr>');
        	   		}else{
        				$('#c_tags_show table').html('<tr><td>地点</td><td>'+result.city+'</td></tr>'+
                                '<tr><td>领域</td><td>'+result.corpindustry+'</td></tr>'+
                                '<tr><td>规模</td><td>'+result.corpscale+'</td></tr>'+
                                '<tr><td>主页</td><td><a href="http://'+result.website+'" target="_blank">'+result.website+'</a></td></tr>');
        			}
            		$('#c_tags_show').show();
            		$('#c_tags_edit').hide();
            	}else{
            		if(result.errmsg == 'error'){
            			alert("保存失败");
            		}else{
            			alert(result.errmsg);
            		}
            	}
            	$(form).find(":submit").attr("disabled", false);
     	       },  
     	       error : function () {  
     	       		return;
     	       }  
			});
		}
	});

	//select框
	$(document).click(function() {
		$('#box_sca').hide();
		$('#box_fin').hide();
		$('#typeForm .selectBoxShort').hide();
		$('#select_ind').removeClass('select_tags_focus');
		$('#select_fin').removeClass('select_tags_focus');
		$('#select_sca').removeClass('select_tags_focus');
	});

	//选行业(可选)
	var count = 0;
	$('#select_ind').bind('click', function(e) {		
		if(count%2==0){
			e.stopPropagation();
			$(this).addClass('select_tags_focus');
			$('#select_fin').removeClass('select_tags_focus');
			$('#select_sca').removeClass('select_tags_focus');
			$('#box_ind').show();
			$('#box_sca').hide();
			$('#box_fin').hide();
		}else{
			$('#box_ind').hide();
		}
		count++;
	});
	$("#box_ind ul li").click(function(){
		$("#select_ind").val($(this).text());
		$("#industryField").val($(this).text());
		$('#box_ind').hide();
		count =0;
	});
	/*$('#box_ind').on(
			'click',
			'ul li',
			function(e) {
				e.stopPropagation();
				var industry = [];
				if ($(this).hasClass('current')) {
					$(this).removeClass('current');
					$('#box_ind li.current').each(function() {
						industry.push($(this).text());
					});
					$('#select_ind').val(industry.join());
					$('#industryField').val(industry.join());
				} else {
					if ($(this).siblings('li.current').length == 0) {
						$(this).addClass('current');
						$('#box_ind li.current').each(function() {
							industry.push($(this).text());
						});
						$('#select_ind').val(industry.join()).removeClass(
								'select_tags_focus');
						$('#industryField').val(industry.join());
						$('#box_ind').hide();
					}else if($(this).siblings('li.current').length >= 1){
//						alert("行业只能选取一个");
					}
				}
			});
			*/


	//选规模
	$('#select_sca').bind('click', function(e) {
		e.stopPropagation();
		$(this).addClass('select_tags_focus');
		$('#select_ind').removeClass('select_tags_focus');
		$('#box_sca').show();
		$('#box_fin').hide();
		$('#typeForm .selectBoxShort').hide();
		$('#box_ind').hide();
	});
	$('#box_sca').on('click', 'ul li', function(e) {
		e.stopPropagation();
		var sca = $(this).text();
		$('#select_sca').val(sca).removeClass('select_tags_focus');
		$('#companySize').val(sca);
		$('#box_sca').hide();
	});

	$('#box_fin,#box_sca').bind('click', function(e) {
		e.stopPropagation();
	});

	//选择行业领域
	var cancelButton = null;
	$(".c_stages").on("click", "#select_fin", function(e) {
		e.stopPropagation();
		/*
		 * $(this).addClass('select_tags_focus');
		 * $('#select_ind').removeClass('select_tags_focus');
		 * $('#select_sca').removeClass('select_tags_focus');
		 */
		$('#box_fin').show();
		//$('#stagesList .selectBoxShort').hide();
		$('#box_sca').hide();
		$('#box_ind').hide();
	})
	$('.c_stages #typeForm #box_fin').on('click', 'li', function(event) {
		event.stopPropagation();
		var _this = $(this);
		loop(_this);
	});
	function loop(ele) {
		var fin = ele.text();
		var ul = ele.parents("div.stageSelect").next("ul#stagesList");
		$('#select_fin').val(fin);// .removeClass('select_tags_focus');
		$('#companyType').val(fin);
		var val = $("#select_fin").val();
		$('#box_fin').hide();
		
	}

	//选择公司性质
	var typeForm = null;
	$('.c_stages .c_edit').bind('click',
		function() {
			submitStage()
			$(this).hide();
			$("#select_fin").attr("value",corpquality);
			$('.c_stages .stageshow').hide();
			typeForm = $('.c_stages #typeForm').clone();
			$('#typeForm #stagesList').find("li").each(function(i) {
				if ($(this).find("input[type='hidden']").val() == "") {
					$(this).remove();
				}
			})
			if (cancelButton != null) {
				$("#cancelStages").remove();
				$("#typeForm").find("input[type='submit']").after(
						cancelButton);
			}
			$('.c_stages #typeForm').show();
			$('#box_sca').hide();
			
		});

	$('.c_stages').on('click', '.select_invest', function(e) {
		e.stopPropagation();
		$('#box_sca').hide();
		/*
		 * $(this).parents('li').siblings().children('.selectBoxShort').hide();
		 * $(this).siblings('.selectBoxShort').show();
		 */
	});

	// 公司性质 submit
	function submitStage() {
		$('#typeForm').validate(
				{
					/*
					 * onkeyup: false, focusCleanup:true,
					 */
					rules : {
						corpquality : {
							required : true,
							maxlenStr : 50
						}
					},
					messages : {
						corpquality : {
							required : "请选择公司性质",
							maxlenStr : "请选择公司性质"
						}
					},
		/*
		$('.c_stages #typeForm').validate(
		{
			onkeyup : false,
			 focusCleanup:true 
			rules : {
				stageorg0 : {
					required : false,
					 maxlength:200 
					maxlenStr : 50
				}
			},
			messages : {
				stageorg0 : {
					 maxlength:"请输入200字以内的投资机构" 
					maxlenStr : "请选择公司性质"
				}
			},*/
			errorPlacement : function(error, element) {
				error.appendTo(element.parent());
			},
			submitHandler : function(form) {
				/*
				 * $('.c_stages').on('click','.btn_small',function(){
				 * var form = $(this).parents('#typeForm');
				 */
				$(form).find(":submit").attr("disabled", true);
				var uidAndSession = "uid=" + $.cookie("jrqUid")
						+ "&sessionId=" + $.cookie("sessionId");
				var companyType = $("#select_fin").val();
				if(companyType.length<1){
//					alert("请选择公司性质！");
					return;
				}
				switch(companyType)
				{
				case "外商独资": companyType=0;
				break;
				case "中外合资/合作": companyType=1;
				break;
				case "国有企业": companyType=2;
				break;
				case "外企代表处": companyType=3;
				break;
				case "政府机关/非盈利机构": companyType=4;
				break;
				case "事业单位": companyType=5;
				break;	
				case "股份制企业": companyType=7;
				break;	
				case "民营/私企": companyType=8;
				break;	
				case "其它": companyType=6;
				break;	
				}
				var corpid = $.cookie("corpid");
				$.ajax({  
		     	       type : 'post',  
		     	       url : 'saveCompanyInfo.action',  
		     	       dataType : 'json',  
						   data : {
							   params : uidAndSession
								+ '&flag=typeForm'
								+ '&corpid='
								+ corpid
								+ '&company.corpquality='
								+ companyType
							},
		     	  	   success : function (result) {
		     	  		if(result.errcode==0){
		     	  			$('#select_fin',form).val(companyType);
		        			if(result.corpquality != ''){
		        				$("#corpquality").html(result.corpquality);
		                		//$('.reset .stageshow').html('<li>公司性质：<span id="corpquality" class="c5">'+result.corpquality+'</span></li>');
			        		}else{
			        			$("#corpquality").html('');
			        			//$('.reset .stageshow').html('');
			        		}
			        		cancelButton = null;
			        		$(form).hide();
			        		$('.c_stages .stageshow').show();
			        		$('.c_stages .c_edit').show();
			        	}else{
			        		alert("保存失败");
			        	}
			        	$(form).find(":submit").attr("disabled", false);
		     	       },  
		     	       error : function () {  
		     	       		return;
		     	       }  
				});
			}
		});
	}
	$('#cancelStages').on('click', function() {
		var stageWrapper = $(this).parents('.c_stages');
		cancelButton = $(this).clone(true);
		stageWrapper.children('dd').find('form').remove();
		stageWrapper.children('dd').append(typeForm);
		$('.c_stages .stageshow').show();
		$('.c_stages .c_edit').show();
/*		$('#typeForm #box_fin').on('click', 'li', function(event) {
			event.stopPropagation();
			var _this = $(this);
			loop(_this);
		});
		submitStage();*/
	});
	
	/**************************************************************************
	 * B & C 端 公司详情页
	 * 
 	 * 取消编辑公司标签
 	 */
   	
 	//$.cookie('labels', $('#hasLabels').html());
   	/*nancy add companyLabels*/
 	var companyLabels = $('#hasLabels').html();
	$('#cancelLabels').click(function(){
		/*add nancy*/
		$('#label').val('');
		$('#addLabels').hide();
		$('.c_box h3').hide();
		$('#hasLabels li').each(function(){
			$(this).find('i').remove();
		});
		$('#hasLabels').on('mouseenter','li',function(){
			$(this).css({marginRight:'18px',cursor:'default'});
		});
		$('#hasLabels').append('<li class="link">编辑</li>');
		$('#hasLabels').empty().append(companyLabels);
		$(this).parents('.c_detail').removeClass('c_detail_bg');
	});
	/***************************
 	 * 保存编辑公司标签
 	 */
	$('#saveLabels').click(function(){
		/**add nancy**/
		if($.trim($('#label')).length!==0){$('#label').val('');}
		/**end nancy**/
		var uidAndSession = "uid=" + $.cookie("jrqUid") + "&sessionId=" + $.cookie("sessionId");
		var corpid = $.cookie("corpid");
		var labels = [];
		var _this = $(this);
		$('#hasLabels li').each(function(){
			labels.push($(this).children('span').text());
		});
		$.ajax({
        	type:'POST',
        	data: {
        		params : uidAndSession
				+ '&flag=saveLabels'
				+ '&corpid='
				+ corpid
				+'&company.label='
				+labels.join()
				},
        	url:'saveCompanyInfo.action'
        }).done(function(result) {
        	if(result.errcode='0'){
        		$('#addLabels').hide();
        		$('.c_box h3').hide();
        		$('#hasLabels li').each(function(){
        			$(this).find('i').remove();
        		});
        		$('#hasLabels').on('mouseenter','li',function(){
        			$(this).css({marginRight:'18px',cursor:'default'});
        		});
        		$('#hasLabels').append('<li class="link">编辑</li>');
        		companyLabels = $('#hasLabels').html();
        		_this.parents('.c_detail').removeClass('c_detail_bg');
       		}else{
//				alert("保存失败");
        	}
        });
	});
	//编辑标签
	$('#hasLabels').on('click','.link',
		function() {
			/** add nancy* */
			// 判断IE浏览器版本
			if (navigator.userAgent.indexOf("MSIE") > 0) {
				if (navigator.userAgent.indexOf("MSIE 7.0") > 0
						|| navigator.userAgent.indexOf("MSIE 8.0") > 0
						|| navigator.userAgent.indexOf("MSIE 9.0") > 0) {
					var placeholder = $('#label').attr('placeholder');
					$('#label').val(placeholder).css('color', '#777777');
				}
			}

			$('#changeLabels').trigger('click');
			$('.c_detail').addClass('c_detail_bg');
			$('#addLabels').show();
			$('.c_box h3').show();
			$(this).remove();
			$('#hasLabels li').each(function() {
				$(this).append('<i>x</i>');
			});

			$('#hasLabels').on('mouseenter', 'li', function() {
				$(this).css({
					marginRight : '6px',
					cursor : 'pointer'
				});
			});
			$('#hasLabels').on('mouseleave', 'li', function() {
				$(this).css({
					marginRight : '18px',
					cursor : 'pointer'
				});
			});
		});
	//标签取消
	$('#cancelLabels').click(function() {
		/* add nancy */
		$('#label').val('');
		$('#addLabels').hide();
		$('.c_box h3').hide();
		$('#hasLabels li').each(function() {
			$(this).find('i').remove();
		});
		$('#hasLabels').on('mouseenter', 'li', function() {
			$(this).css({
				marginRight : '18px',
				cursor : 'default'
			});
		});
		$('#hasLabels').append('<li class="link">编辑</li>');
		//$('#hasLabels').empty().append(companyLabels);
		$(this).parents('.c_detail').removeClass('c_detail_bg');
	});
	//选择标签
	$('#addLabels ul').on('click','li',
		function() {
			/** add nancy* */
			var judge = true;
			var labelVal = $(this).text();
			if (!$(this).hasClass('curr')) {
				$(this).addClass('curr');
				$('#hasLabels li').each(function() {
					if ($(this).children('span').text() == labelVal) {
						judge = false;
						return judge;
					}
				});
			} else {
				$('#hasLabels li').each(function() {
					if ($(this).children('span').text() == labelVal) {
						judge = false;
						return judge;
					}
				});
			}
			if (judge) {
				$('#hasLabels').append(
						'<li><span>' + labelVal + '</span><i>x</i></li>');
			} else {
//				alert("此标签已存在，请重新输入");
			}
			/** end nancy* */
	});
	//删标签
	$('#hasLabels').on('click', 'li i', function() {
		$(this).parent().remove();
	});
	/***************************
 	 * 贴标签
 	 */
	$('#add_label').bind('click',function(){
		var _label = $('#zdylabel');
		var labelVal = $.trim(_label.val());
		var judge = true;
		if( labelVal.length<=6 && labelVal.length > 0){
			$('#hasLabels li').each(function(){
				if($('span',this).text() == labelVal){
					judge = false;
				}
			});
			if(judge){
				$('#hasLabels').append('<li><span>'+labelVal+'</span><i>x</i></li>');
			}else{
//				alert('此标签已存在，请重新输入');
			}
			_label.val('');
		}else{
//			alert("请输入1-6字的自定义标签");
			/*alert("请输入1-6个字的公司标签");*/
		}
	});
	
	/***************************
 	 * enter键贴标签
 	 */
	$('#zdylabel').keydown(function(e){
		if(e.which == 13){
			$('#add_label').trigger('click');
		}
	});
});